-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed compiling of constructor and type reference. Fixed unary plus/minus. Added node.getRaw(). #14
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ukrbublik sorry for the delayed response, but thank you for this PR!
I have just a few minor requests and a question for you, otherwise this looks good to go.
throw { | ||
name: 'MethodNotImplementedException', | ||
message: 'BeanReference: Not implemented' | ||
message: 'ConstructorReference: Not implemented' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this throw be removed now since it's implemented? It looks like it's unreachable anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's implemented only for array construction:
spel2js/src/ast/ConstructorReference.js
Line 51 in f5b05db
if (isArray && args.length <= 1) { |
For other classes it will throw
ConstructorReference: Not implemented
(just renamed typo here BeanReference
-> ConstructorReference
)
if (args.length == 1) { | ||
return compiledArgs[0]; | ||
} else { | ||
return dimension ? new Array(dimension) : []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return dimension ? new Array(dimension) : []; | |
return dimension ? [dimension] : []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line would create an empty array with dimension, not an array with 1 element.
Example in console:
> new Array(4)
Array(4) [ <4 empty slots> ]
length: 4
> [3]
Array [ 3 ]
0: 3
length: 1
See test for evaluating new int[3]
:
spel2js/test/spec/SpelExpressionEvaluator.spec.js
Lines 906 to 918 in f5b05db
it('should create new empty array with dimension', ()=>{ | |
//given | |
let context = {}; | |
//when | |
let newArray = evaluator.eval('new int[3]', context); | |
//then | |
expect(newArray.length).toEqual(3); | |
}); | |
}); | |
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right, thanks
Thanks, @ukrbublik, looks good to me. I'll publish a new version with these changes shortly. |
Thanks @benmarch 👍 |
Cannot read property 'setParent' of undefined
when trying to compile expression with constructor or type referenceFixed urary plus/minus. Resolves issue Expression with negative value failed to compile #12
Added
node.getRaw()
for some types to get raw value (eg.propertyName
forproperty
node).Can be used for debugging compiled expressions.
Used in https://github.com/ukrbublik/react-awesome-query-builder to convert compiled expression to internal store format.
Added unit tests